﻿using BCCommon.Enums;
using BCDto.Common.UploadFileRecord;
using BCDto.UploadHandleComponent;
using BCService.Common.UploadFileRecord;
using System;
using System.Collections.Generic;
using System.Text;

namespace BCService.UploadHandleComponent.OfficeHandle
{
    /// <summary>
    /// 办公文件处理
    /// </summary>
    public class OfficeHandle : IUploadHandle
    {
        private readonly IUploadFileRecordService uploadFileRecordService;
        private UploadFileDto uploadFileDto;

        public OfficeHandle(IUploadFileRecordService uploadFileRecordService)
        {
            this.uploadFileRecordService = uploadFileRecordService;
        }

        public void CheckData(UploadFileDto uploadFileDto)
        {
            this.uploadFileDto = uploadFileDto;
        }

        public UploadResponseDto Process(UploadFileDto uploadFileDto)
        {
            string medialId = string.Empty;
           
            UploadFileRecordDto uploadFileRecordDto = new UploadFileRecordDto();
            uploadFileRecordDto.UploadFileRecordNo = this.uploadFileDto.FileName;
            uploadFileRecordDto.FileSize = this.uploadFileDto.ContentLength;
            uploadFileRecordDto.FilePath = this.uploadFileDto.DirectoryPath;
            uploadFileRecordDto.FileUrl = this.uploadFileDto.Src;
            uploadFileRecordDto.FileSuffix = this.uploadFileDto.FileSuffix;
            uploadFileRecordDto.FileUsage = this.uploadFileDto.Usage.ToString();
            uploadFileRecordDto.RemarkType = this.uploadFileDto.Usage.Equals("Self") ? "" : this.uploadFileDto.RemarkType.ToString();
            uploadFileRecordDto.WebsiteName = this.uploadFileDto.WebsiteName;
            uploadFileRecordDto.WebsiteFileDirectory = this.uploadFileDto.WebsiteFileDirectory;
            uploadFileRecordDto.WebsiteFullName = this.uploadFileDto.WebsiteFullName;
            this.uploadFileRecordService.Add(uploadFileRecordDto);
            return new UploadResponseDto()
            {
                Message = medialId
            };
        }
    }
}
